package top.yongyan0624.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.yongyan0624.mapper.DeptMapper;
import top.yongyan0624.pojo.Dept;
import top.yongyan0624.pojo.Dept;
import top.yongyan0624.service.DeptService;

import java.util.List;

/**
 * @author Yongyan
 * @description: TODO
 * @date 2020/12/25
 **/

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    public Integer addDept(Dept dept) {
        return deptMapper.addDept(dept);
    }

    public Integer deleteDept(Integer id) {
        return deptMapper.deleteDept(id);
    }

    public Integer updateDept(Dept dept) {
        return deptMapper.updateDept(dept);
    }

    public List<Dept> findAllDept() {
        List<Dept> deptList = deptMapper.findAllDept();
        for (Dept dept : deptList) {
            Integer totalStudent = deptMapper.totalStudent(dept.getDno());
            dept.setTotalStudent(totalStudent);
        }
        return deptList;
    }

    public PageInfo<Dept> findAllDept(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Dept> deptList = deptMapper.findAllDept();
        return new PageInfo<Dept>(deptList);
    }

    public Dept findById(Integer id) {
        return deptMapper.findById(id);
    }

    public List<Dept> findByName(String name) {
        return deptMapper.findByName(name);
    }

    public List<Dept> findDept(Dept dept) {
        return deptMapper.findDept(dept);
    }

    public Integer totalDept() {
        return deptMapper.totalDept();
    }
}
